import bisect
class Solution(object):
    def minOperations(self, target, arr):
        target = {num:index for index, num in enumerate(target)}
        st = []
        for num in arr:
            if num in target:
                now_index = target[num]
                st_index = bisect.bisect_left(st, now_index)
                if st_index == len(st):
                    st.append(now_index)
                else:
                    st[st_index] = now_index
        return len(target) - len(st)
        
data = Solution()
target = [17,18,14,13,6,9,1,3,2,20]
arr = [18,15,14,6,6,13,15,20,2,6]
print(data.minOperations(target, arr))